
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class GpInputS extends JDialog implements ActionListener 
{
	JTextField stockInput;
	JList list;
	DefaultListModel model;
	GpTickerS gpTicker;
	
	public GpInputS(GpTickerS gpTicker, String[] stocks)
	{
		super();
		this.gpTicker = gpTicker;
		this.setLayout(new BorderLayout());
		model = new DefaultListModel();
		if (stocks != null)
		{
			for (int i = 0; i < stocks.length; i ++)
				model.addElement(stocks[i]);
		}
		list = new JList(model);
		JScrollPane pane = new JScrollPane(list);
		add(pane, BorderLayout.NORTH);
		
		Panel p = new Panel();
		
		stockInput = new JTextField(6);
		p.add(stockInput);
		
		JButton addButton = new JButton("add");
		addButton.addActionListener(this);
		p.add(addButton);

		JButton removeButton = new JButton("remove");
		removeButton.addActionListener(this);
		p.add(removeButton);

		add(p, BorderLayout.SOUTH);
	}
	
	public void actionPerformed(ActionEvent e)
	{
		if (e.getActionCommand() == "add")
		{
			model.addElement(stockInput.getText());
			gpTicker.update();
			
		}
		else if (e.getActionCommand() == "remove")
		{
			model.remove(list.getSelectedIndex());
			gpTicker.update();
		}
	}
	
	public Object[] getList()
	{
		return model.toArray();
	}
	
	
	
}
